package com.swt.controller.S_controller;

import com.alibaba.fastjson.JSON;
import com.swt.domain.Aboutcourse;
import com.swt.domain.User;
import com.swt.service.S_service.GetInfoService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

@Controller
public class GetInfoController {
    /*注入service*/
    @Resource(name = "S_getInfoService")
    private GetInfoService getInfoService;
    /*获取该店铺下的该用户的预约信息*/
    @RequestMapping("/S_getInfo")
    @ResponseBody
    public String getInfo(int clubid, HttpServletRequest request){
        /*获取用户id*/
        User user = (User)request.getSession().getAttribute("USER_SESSION_KEY");
        int userid=user.getUserId();
        /*调用service*/
        List<Aboutcourse> list = getInfoService.getInfo(clubid, userid);
        String aboutcourse=JSON.toJSONString(list);
        return aboutcourse;
    }
    /*删除预约信息controller*/
    @RequestMapping("/S_deleteInfo")
    public String deleteInfo(int aboutcourseId){
        /*删除的之前需要将对应课程的数量+1*/
        /*删除信息*/
        getInfoService.deleteInfo(aboutcourseId);
        return "redirect:user/info.html";
    }
}
